cmake_minimum_required(VERSION 3.28)
project(Network_Traffic_Processing_V1
        DESCRIPTION "Network_Traffic_Processing 统计"
        LANGUAGES CXX
        HOMEPAGE_URL "https://")
set (app_name "Network_Traffic_Processing_V1")

set(CMAKE_CXX_STANDARD 17)

# include目录要适应项目目录结构，有时要根据头文件中的路径灵活调整。设置 第三方 库的头文件搜索路径
include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_SOURCE_DIR}/include")
include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_SOURCE_DIR}/include/libtins")
include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_SOURCE_DIR}/include/libpcap")

# 添加库目录
link_libraries(${CMAKE_SOURCE_DIR}/lib/spdlog)
link_libraries(${CMAKE_SOURCE_DIR}/lib/libtins)
link_libraries(${CMAKE_SOURCE_DIR}/lib/libpcap)

# 添加源代码
aux_source_directory(./ SRC_FILES)
aux_source_directory(${PROJECT_SOURCE_DIR}/src SRC_FILES)
aux_source_directory(${PROJECT_SOURCE_DIR}/src/main SRC_FILES)
aux_source_directory(${PROJECT_SOURCE_DIR}/src/utils SRC_FILES)

# 可执行文件的路径
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")

if(MSVC)
    message("设置msvc支持utf8")
    execute_process(COMMAND system("chcp 65001"))
    #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /source-charset:utf-8") # 指定了这个要求所有文件的编码都要为utf8
    #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /source-charset:utf-8") # 指定了这个要求所有文件的编码都要为utf8
    # 同时指定了 /source-charset、/execution-charset 或 /utf-8 编译器选项，但是指定的字符集与文件的实际编码不兼容
    SET(CMAKE_BUILD_TYPE "Debug")
    #set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O1")
    #set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /O1") # 默认02优化级别
ELSE ()
    message("设置gcc支持utf8，启用调试")
    # 启用调试
    SET(CMAKE_BUILD_TYPE "Debug")
    SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -gdwarf-4 -gstrict-dwarf")
    SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
    SET(CMAKE_CXX_FLAGS "-fPIC -DLINUX  -m64 -w -static-libstdc++ -O2 -g") # -std=c++11 stdc++ 静态依赖，可以不依赖与系统的 libc++
    #SET(CMAKE_CXX_FLAGS "-finput-charset=GBK")
endif ()

# 确保链接到多线程库
if(MSVC)
    # msvc命令编译 cl main.cpp /EHsc /MT
    #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MT")
endif()


add_executable(${app_name} ${SRC_FILES})

if (MSVC)
    message("操作系统类型 = ${CMAKE_SYSTEM_NAME}")
    target_link_libraries(${app_name} PUBLIC
            "${CMAKE_SOURCE_DIR}/lib/spdlog/win/spdlog.lib"
            )
ELSE()
    message("操作系统类型 = ${CMAKE_SYSTEM_NAME}")
    target_link_libraries(${app_name} PUBLIC
            "${CMAKE_SOURCE_DIR}/lib/spdlog/linux/libspdlog.a"
            "${CMAKE_SOURCE_DIR}/lib/libpcap/linux/libpcap.a"
            "${CMAKE_SOURCE_DIR}/lib/libtins/linux/libtins.a"
            pthread
            )
endif ()

# 调试
message("===【调试】===")
message("模块名===${app_name}")
message("CMAKE_SOURCE_DIR===${CMAKE_SOURCE_DIR}")
message("PROJECT_SOURCE_DIR===${PROJECT_SOURCE_DIR}")
message("SRC_FILES===${SRC_FILES}")
message(STATUS "引用的第三方库: ${LIBRARIES}")
